package dk.wifiathome;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

public class positionListGui extends ListActivity {

	private listDataAdapter list_adapter;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		registerForContextMenu(getListView());

		setContentView(R.layout.positionlist);

		positionList app = (positionList) getApplication();

		this.list_adapter = new listDataAdapter(this, R.layout.listrow, app
				.getPositionArrayList());
		setListAdapter(this.list_adapter);

		this.registerForContextMenu(this.getListView());

	}

	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		// Get the item that was clicked

		Toast.makeText(this, "You selected item number: " + position,
				Toast.LENGTH_SHORT).show();

	}

	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenu.ContextMenuInfo menuInfo) {
		
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.positionlistgui, menu);

	}

	/* Handles item selections */
	public boolean onContextItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.deleteListItem: {
				final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
				positionList app = (positionList) getApplication();
				app.RemovePositionListEntry(info.position);
				setListAdapter(this.list_adapter);
				Toast.makeText(this, "Deleted item number: " + info.position, Toast.LENGTH_SHORT).show();
	
			}
		}
		return true;
	}
}
